

function cart_deal(){
	
	var sum_good_price = 0.00;//总价
	
	//（每个店铺全选效果）为每个父店铺元素添加响应
	this.select = function(obj){
		
		for(var i = 0 ; i<obj.length;++i){
			
			obj[i].addEventListener("click",function(){
				
				//console.log($(this).attr("val"));
				var f = $(this).attr("val");
				if(f == 0){
					//console.log("in if");
					
					//效果
					setcolor(this,f);
					
					var items = $(this).children(".store_id");
					var store_id = items.val();
					//每个店铺下面的商品
					var store_goods = $(".store_item_radio"+store_id);
					
					//子效果
					for(var i = 0 ; i < store_goods.length ; ++i){
						
						var store_goods_item = store_goods.get(i);
						setcolor(store_goods_item,f);
						
						var fl = $(store_goods_item).attr("m");
						//console.log("fl is "+fl)
						//计算价格
						if(fl == 0){
							//console.log("计算加");
							calculation_price(store_goods_item,0);
						}
						
						
						//console.log(sum_good_price);
					}
					
				}else{
					
					//把全选选项设成原始效果
					var sum_radio_val = $(".sum_radio").attr("val");
					if(sum_radio_val == 1){
						setcolor($(".sum_radio").get(0),f);
					}
					
					var f = 2;
					//效果
					setcolor(this,f);
					
					var items = $(this).children(".store_id");
					var store_id = items.val();
					
					//每个店铺下面的商品
					var store_goods = $(".store_item_radio"+store_id);
					
					//子效果
					for(var i = 0 ; i < store_goods.length ; ++i){
						
						var store_goods_item = store_goods.get(i);
						
						setcolor(store_goods_item,f);
						
						var fl = $(store_goods_item).attr("m");
						//console.log("fl is "+fl)
						//计算价格
						if(fl == 1){
							//console.log("计算加");
							calculation_price(store_goods_item,1);
						}
						
						//console.log(sum_good_price);
						//store_goods_item.flag = 1;
					}
					
					//this.flag = 1;
				}
				
			});
		}
	}
	
	
	//每个子商店选择效果
	this.chilSelect = function(obj){
		//console.log(obj);
		
		for(var i = 0 ; i < obj.length; ++i ){
			var radio_item = obj.get(i);
			
			radio_item.addEventListener('click',function(){
				var flag = $(this).attr("val");
				if(flag == 0){
					//console.log(this);
					setcolor(this,flag);
					calculation_price(this,0);//加
				}else{
					setcolor(this,this.flag);
					calculation_price(this,1);//减
				}
				
				
			});
			//console.log(radio_item);
		}
		
	}
	
	//通过子节点响应父节点    -----效果响应，只关注效果
	this.listenChil = function(){
		
		var warp = $(".wrap");
		var collect = warp.children(".collect");
		var index = 0 ;
		
		for(var i = 0 ;i < collect.length; ++i){
			
			var collections = collect.get(i);//获取每个商家
			var radio_items = $(collections).find(".radio");//获取每个商家下的radio
			
			//为每个商家的radio添加响应
			for(var j = 0 ; j < radio_items.length ; ++j ){
				radio_items.get(j).addEventListener('click',function(){
					/*index = index + 1;
					if(index == )*/
					
					var radio_par_collect = $(this).parents(".collect");
					var r_num = radio_par_collect.find(".collect_content");
					var radio_sum = radio_par_collect.find(".radio");//按钮总数
					var radio_length = radio_sum.length;
					var temp = 0 ;
					//遍历
					radio_sum.each(function(){
						var attr = $(this).attr("val");
						temp = temp + Number(attr);
					});
					if(temp == radio_length){
						var header = radio_par_collect.siblings(".header");
						var h_radio = header.find(".store_radio");
						setcolor(h_radio.get(0),0);
						//console.log(h_radio);
					}else if(temp == 0){
						console.log(radio_par_collect);
						var header = radio_par_collect.siblings(".header");
						var h_radio = header.find(".store_radio");
						setcolor(h_radio.get(0),1);
					}
					
					//console.log(radio_sum);
					
				});
			}
			
			
			
		}
		
	}
	
	
	
	//全选响应
	this.selectAll = function(){
		
		
		$(".allselect").get(0).addEventListener('click',function(){
			var flag = $(".allselect .sum_radio ").attr("val");
			//console.log(flag)
			if(flag == 0){
				
				setcolor($(".allselect .sum_radio ").get(0),flag);
				var store_radio = $(".store_radio");
				//情况总数
				//sum_good_price = 0.00;
				//把值全部设成0
				
				store_radio.each(function(){
					$(this).attr("val",0);
					$(this).click();
				});
				
			}else{
				//console.log(flag);
				setcolor(this,flag);
				
				var store_radio = $(".store_radio");
				store_radio.each(function(){
					$(this).click();
				});
			}
			
		});
		
		
		
	}
	
	
/**
 * 选中的效果
 * @param {this对象，非jq对象} obj
 * @param {标致位1或者2} flag
 */
function setcolor(obj,flag){
	
	if(flag == 0){
		//效果
		$(obj).children(".hui-icons").css("display","block");
		$(obj).css("background","red");
		$(obj).css("border-color","red");
		$(obj).attr("val","1");
	}else{
		$(obj).children(".hui-icons").css("display","none");
		$(obj).css("background","none");
		$(obj).css("border-color","#A9A9B0");
		$(obj).attr("val","0");
	}
}



/**
 * 计算总价
 * @param {非jq的obj} obj
 * @param {标致位1或者2} flag
 */
function calculation_price(obj,flag){
	//加
	if(flag == 0){
		var price_obj = $(obj).children(".goods_price");
		var price = price_obj.val();
		price = Number(price);
		sum_good_price = sum_good_price + price;
		$(".cart_price").html("¥"+sum_good_price);
		$(obj).attr("m","1");

		
	}else{
		//减
		var price_obj = $(obj).children(".goods_price");
		var price = price_obj.val();
		price = parseFloat(price);
		sum_good_price = ((sum_good_price*10000) - (price*10000))/10000 ;
		$(".cart_price").html("¥"+sum_good_price);
		$(obj).attr("m","0");
	}
	
}


//监听每个按钮的响应
this.btnclick = function(){
	var radios = $(".radio");
	
	radios.each(function(){
		$(this).get(0).addEventListener('click',function(){
			
			var temp = 0;
			
			//判断是否全选了  或者  全不选
			radios.each(function(){
				
				var i = $(this).attr("val");
				i = Number(i);
				temp = temp + i;
				
			});
			
			if(temp == radios.length){
				//console.log("全选");
				setcolor($(".sum_radio"),0);
				
				
			}else{
				//console.log("不全选");
				setcolor($(".sum_radio"),1);
			}
			
		});
	});
	
}


	
	
}

